<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.Map" %>
<%@ page import="domain.Product" %>
<%@ page import="java.lang.String" %>
<%--
  Created by IntelliJ IDEA.
  User: ThinkPad
  Date: 2021/12/25
  Time: 21:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false"%>
<html>
<head>
    <title>订单结算与复核</title>
</head>
<body>
<%@include file="head.jsp"%>
<%
    Map<Product,Integer> cart = (Map<Product, Integer>) session.getAttribute("cart");
    for(Map.Entry<Product,Integer> entry:cart.entrySet()){
        if (entry.getKey().getCount()<entry.getValue()){
            out.print("<script>alert(\"非常抱歉，您的购物车中至少有商品“"+entry.getKey().getName()+"“库存不足，请移步购物车界面修改购买数目！\");" +
                    "window.location=\"cart.jsp\";</script>");
        }
    }
%>
<br />
<div style="text-align: center;font-weight: bold;font-size: x-large;color: forestgreen">
    You're almost there!<br />
    就要完成了！在下订单之前，您有机会复核您的订单条目：
</div>
<br />
<table style="border: 2px lightskyblue solid;width: 60%;margin-left: 20%">
    <tr>
        <td style="width: 20%">序号</td>
        <td style="width: 30%">名称</td>
        <td style="width: 20%">价格</td>
        <td style="width: 20%">数量</td>
        <td style="width: 10%">小计</td>
    </tr>
</table>
<%-- 循坏输出商品信息 --%>
<c:set var="total" value="0" />
<c:forEach items="<%=cart%>" var="entry" varStatus="vs">
    <table style="width: 60%;margin-left: 20%">
        <tr>
            <td style="width: 20%;">${vs.count}</td>
            <td style="width: 30%;">${entry.key.name }</td>
            <td style="width: 20%;">${String.format("%.2f", entry.key.price)}</td>
            <td style="width: 20%;">${entry.value}</td>
            <td style="width: 10%;">${String.format("%.2f", entry.key.price*entry.value)}</td>
        </tr>
    </table>
    <c:set value="${total+entry.key.price*entry.value}" var="total" />
</c:forEach>
<table style="border: 2px lightskyblue solid;width: 60%;margin-left: 20%">
    <tr>
        <td style="text-align: right;padding-right: 40px">
            <div style="color: orange;font-weight: bold">合计：&nbsp;&nbsp;￥${String.format("%.2f", total)}</div>
        </td>
    </tr>
</table>
<br /><br />
<div style="color: red;text-align: center;font-weight: bold">
    请仔细检查以上信息，确认无误后，填写以下收货信息并完成支付：
</div>
<br />
<form name="checkout" action="${pageContext.request.contextPath}/success.jsp" method="post">
    <table style="width: 50%;margin-left: 25%">
        <tr>
            <td style="width: 250px"><div style="text-align: right">收货人姓名：</div></td>
            <td><label>
                <input type="text" name="rname" required>
            </label></td>
        </tr>
        <tr>
            <td style="width: 250px"><div style="text-align: right">收货人地址：</div></td>
            <td><label>
                <input type="text" name="raddr" required>
            </label></td>
        </tr>
        <tr>
            <td style="width: 250px"><div style="text-align: right">收货人电话：</div></td>
            <td><label>
                <input type="tel" name="rphone" required>
            </label></td>
        </tr>
        <tr>
            <td style="width: 250px"><div style="text-align: right">收货人邮箱：</div></td>
            <td><label>
                <input type="email" name="remail" required>
            </label></td>
        </tr>
    </table>
    <br />
    <input type="submit" value="付款并提交" style="margin-left: 48%" >
</form>
<br />
<a href="${pageContext.request.contextPath}/cart.jsp" style="font-size: small;margin-left: 40%">&lt;订单有误，返回修改</a>
<%@include file="tail.jsp"%>
</body>
</html>
